# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

pkgname=haskell-src-meta
pkgver=0.8.11
pkgrel=26
pkgdesc="Parse source to template-haskell abstract syntax"
url="https://github.com/haskell-party/haskell-src-meta"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-src-exts' 'haskell-syb' 'haskell-th-orphans')
makedepends=('ghc' 'haskell-hunit' 'haskell-tasty' 'haskell-tasty-hunit')
source=("https://hackage.haskell.org/packages/archive/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('564d906649fd473e94d97735dddc17d4b98dcdd98accee6aac5305b4bddf7ded12157590dfc73c2d144a8c6bd83ce9037a41df3f4e0e416086052b50bdadc0f0')

build() {
    cd $pkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $pkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $pkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
